<%@page import="transfer.Commodity"%>
<%@page import="content.CommodityContent"%>

<%
    String idParameter = request.getParameter("id");
    Commodity commodity = null;
    try {
         commodity = CommodityContent.getCommodity(new Integer(idParameter));
    } catch(Exception exc) {
        return;
    }
    String imagePath = "../images/commodity/" + commodity.getImage();
    double price = commodity.getPrice().doubleValue();
    boolean out_of_production = commodity.getOutOfProduction().booleanValue();
%>
<div class="img-big-view" id="id_commodity" catid="<%= commodity.getCategory().getIdCategory() %>" value="<%= commodity.getIdCommodity() %>">
    <div class="float_left">
        <img id="picture_commodity" src="<% out.print(imagePath);%>">
        <%
            if (!out_of_production) {
        %>
        <div></div><input type="button" value="Change Picture" id="add-picture" onclick="$('#selectFile').click()"/>
        <form id="form-image" enctype="multipart/form-data" action="PictureLoader" method="post" class="hidden">
            <div></div><input onchange="fileSelected(this)" name="imageSelection" type="file" hidden="true" id="selectFile" accept="image/x-png, image/jpeg" /><br/>
            <input id="commodity_id" name="idCommodity" value="<%= commodity.getIdCommodity() %>"/>
            <input id="file_name" name="fileName" value=""/>
        </form>
        <%
            }
        %>
    </div>
</div>
<div class="float_left" style="width: 620px" >    
    <br/><br/>
    <div>
    <div class="table-view">
        <H3>
            <div>Name:<span class="text-red">*</span></div> <input id="name_commodity" type="text" required="" value="<%= commodity.getNameCommodity() %>"/><br/>
        </H3>
        </div>
    </div>
    <div style="margin-top: 15px;">
    <div class="table-view">
        <H3>
            <div>Category:</div> <input disabled="disabled" type="text" required="" value="<%= commodity.getCategory().getNameCategory() %>"/> <br/>
        </H3> 
        </div>
    </div>
    <div style="margin-top: 15px;">
        <div class="table-view">
        <H3>
            <div>Price:<span class="text-red">*</span></div> <input onkeydown="javascript: return price_commodity_changed(event)" id="price_commodity" type="text" required="" value="<%= commodity.getPrice() %>"/><br/>
        </H3>
        </div>
    </div>
</div>        

<div class="description">
    <H3>
        <div style="vertical-align: top;">Description:<span class="text-red">*</span></div> <textarea id="desc_commodity" style="height: 250px; width: 804px;" ><%= commodity.getDescription() %></textarea><br/>    
    </H3>
</div>
<%
    if (out_of_production) {
%>
    <script>
        $('#name_commodity').prop('disabled', 'disabled');
        $('#price_commodity').prop('disabled', 'disabled');
        $('#desc_commodity').prop('disabled', 'disabled');

    </script>
<%
    }
%>